/**
 * 
 */
package com.scpii.universal.hibernate.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.dto.TypeDto;
import com.scpii.universal.hibernate.dao.TypeDao;
import com.scpii.universal.hibernate.entity.TypeTab;

/**
 * genericWeb
 * @author weny
 * 2012-7-6上午11:07:42
 */
@Repository
public class TypeDaoImpl extends BaseDaoImpl<TypeTab, Integer> implements TypeDao {

	@SuppressWarnings("unchecked")
	@Override
	public List<TypeDto> getMoreTypeList(boolean isHasProduct, boolean isHasActivity) {
		StringBuffer hql = new StringBuffer();
		hql.append("select new com.scpii.universal.dto.TypeDto(t.varTypeName,t.intType)");
		hql.append(" from TypeTab t where t.intDeleteSign=?");
		if(!isHasProduct && !isHasActivity){
			hql.append(" and t.intType not in("+GenericConstants.BASIC_TYPE_ORDER+","+GenericConstants.BASIC_TYPE_ACTIVITY+")");
		} else if (isHasProduct && !isHasActivity){
			hql.append(" and t.intType not in("+GenericConstants.BASIC_TYPE_ACTIVITY+")");
		} else if (!isHasProduct && isHasActivity) {
			hql.append(" and t.intType not in("+GenericConstants.BASIC_TYPE_ORDER+")");
		}
		hql.append(" and t.intParentTypeId=?");
		return getHibernateTemplate().getSessionFactory().getCurrentSession()
				.createQuery(hql.toString()).setParameter(0,
						GenericConstants.DELETE_SIGN_EXIST).setParameter(1,
						GenericConstants.BASIC_TYPE_ID_ACTION_PARENT).list();
	}

}
